package com.hns.can.base.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.base.entity.SysAnnouncementEntity;
import com.hns.can.base.entity.SysAuthorityResourceEntity;
import com.hns.can.base.entity.SysOperateLogEntity;
import com.hns.can.base.entity.SysRoleEntity;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 登录service
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Service
public class LoginService extends CommonService {

	/**
     * 获取数据权限
     * @param roleIdList 角色id
     * @return 数据权限
     * @author:zhangyu
     * @email:zhangyu2222z@sina.cn
     */
    @SuppressWarnings("unchecked")
    public List<String> getAuthorityResource(List<SysRoleEntity> roleIdList){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("roleIdList", roleIdList);
        List<SysAuthorityResourceEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("baseOrgan.getAuthorityResource",map), SysAuthorityResourceEntity.class);
        List<String> organIdlist = new ArrayList<String>();
        if(PubUtil.isNotEmpty(list)){
            for(SysAuthorityResourceEntity entity : list){
                organIdlist.add(entity.getResDataId());
            }
        }
        return organIdlist;
    }
	
    /**
	 * 加载本月系统公告
	 * @return
	 */
	public List<SysAnnouncementEntity> getNoticeList(String corpId){
		Map map = new HashMap();
		map.put("corpId", corpId);
		List<SysAnnouncementEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("systemAnnounce.getNoticeList", map), SysAnnouncementEntity.class);
		return list;
	}
	
	/**
     * @功能说明：添加操作日志记录(例如：登录、注销)
     * @param entity
     * @author:JeffXu
     * @email:835264047@qq.com
     */
    @Transactional
    public void saveSysOperateLog(SysOperateLogEntity entity) {
        commonEntityDao.save(entity);
    }
}
